-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow ConfigurationManager to load when GetEntryAssembly returns null. #32195
Conversation
a35fd47
to
848de30
Compare
...stem.Configuration.ConfigurationManager/src/System.Configuration.ConfigurationManager.csproj
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
848de30
to
e65c559
Compare
...ries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientConfigPaths.cs
Show resolved
Hide resolved
...ries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientConfigPaths.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetModuleFileName.cs
Outdated
Show resolved
Hide resolved
{ | ||
ApplicationUri = uri.LocalPath; | ||
applicationFilename = uri.LocalPath; | ||
if (uri.IsFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is this condition going to be false? As far as I can tell, the above should always going to produce an a filename.
(I understand that you have not added this, but since you are cleaning this up...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like when this code was originally written (dotnet/corefx@7d0bf61), it was using new Uri(exeAssembly.CodeBase)
. It was then changed by https://github.com/dotnet/corefx/pull/20488/files to use Path.Combine(AppDomain.CurrentDomain.BaseDirectory, exeAssembly.ManifestModule.Name)
. But the if (uri.IsFile)
was left.
I can remove the check, and add an assert instead.
FYI - @JeremyKuhne
...ries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientConfigPaths.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had discussed allowing the host to specify this via AppContext property bag, I know that wasn't strictly necessary, but would provide a replacement for AppDomainSetup.ConfigFile.
// Try to find the native entry point. | ||
using (Process currentProcess = Process.GetCurrentProcess()) | ||
{ | ||
ApplicationUri = currentProcess.MainModule.FileName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think MainModule can be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Presuming @ericstj null comment is ok.
On Windows, attempt to find the native host to maintain behavior from netfx. Fix dotnet#25027
caedc60
to
e200bea
Compare
My thinking is that we can add that later if/when it is asked for. We can always add it, but if we put it in now, we wouldn't be able to remove it. I would rather wait until it is required. |
I see, so long as the original issue from #25027 is addressed, along with the issue we were discussing from WPF (dotnet/wpf#2395) then I agree. |
Assembly.GetEntryAssembly() will return
null
when the current process was loaded from a custom/native host. ConfigurationManager should support this scenario, and not throw a PNSE.On Windows, attempt to find the native host to maintain behavior from netfx.
Fix #25027
(Note: probably easiest to review each commit separately. And with whitespace off.)